<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="./favicon.ico">

    <title>学并思留言板(测试版)</title>

    <!-- Bootstrap core CSS -->
    <link href="./template/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap theme -->
    <link href="./template/css/bootstrap-theme.min.css" rel="stylesheet">

    <link rel="stylesheet" href="./template/css/main.css">


    <!-- Custom styles for this template -->


    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body role="document">

    <!-- Fixed navbar -->
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">学并思留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li role="presentation"><a href="#">留言数量 <span class="badge"><?php echo count($db) ?></span></a></li>
            <?php  

            if(isset($_SESSION['username'])){  ?>
                <li><a href="#"> <?php echo $_SESSION['username']; ?></a></li>
                <li><a href="./logout.php">退出</a></li>
             <?php   }else{ ?>
                <li><a href="./login.php">登录</a></li>
             <?php } ?>
            
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container theme-showcase" role="main">
      <div class="row">
        <?php 
          if(isset($notice)){ ?>

            <?php if ($error) { ?>
              <div class="alert alert-danger" role="alert">
                <strong>太伤心了!</strong> 留言失败，因为XXX
              </div>
            <?php } else { ?>
                <div class="alert alert-success" role="alert">
                <strong>你很棒!</strong> 留言成功，再接再厉！
              </div>
            <?php } ?>
         <?php }?>
        <div class="col-sm-12">
          <div class="list-group">
            <?php foreach ($db as $k => $v) { ?>
                
                <!-- <div class="col-sm-10"> -->
                  <li  class="list-group-item">
                    
                      <h4 class="list-group-item-heading"><?php echo $v['username'] ?></h4>
                      <p class="list-group-item-text"><?php echo $v['message'] ?></p> 
                      <a href="./edit.php?id=<?php echo $k; ?>" class="btn btn-sm btn-success">修改</a>
                      <a href="./del.php?id=<?php echo $k; ?>" class="btn btn-sm btn-danger">删除</a>
                  </li>
                <!-- </div> -->
                <!-- <div class="col-sm-2">
                    <a href="" class="btn btn-lg btn-success">修改</a>
                </div> -->


            <?php } ?>

          </div>
        </div><!-- /.col-sm-4 -->

       <?php if(isset($_SESSION['username'])){  ?>
                
            <form class="form-inline" action="" method="post" name="ajax">
              <div class="col-sm-12">
                  <div class="form-group">
                    <label for="exampleInputName2">昵称：</label>
                    <input type="text" class="form-control" id="exampleInputName2" placeholder="楼上的寡妇" name="username">
                  </div>
                  <p class="btn btn-default ajax">发布</p>
              </div>
              <div class="col-sm-12">
                <textarea class="form-control message" rows="5" name="message"></textarea>
              </div>
              
            </form>


             <?php   }else{ ?>
                <li>还没有登录，请先<a href="./login.php">登录</a></li>
             <?php } ?>

      </div>
    </div> <!-- /container -->
    <script src="./template/js/jquery.min.js"></script>
    <script src="./template/js/bootstrap.min.js"></script>
    <script src="./template/js/main.js"></script>
  </body>
</html>
